package com.zjw.hyphenateui.helper;

import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;

import com.example.havi.interfaces.HyphenateLibraryCallBack;
import com.tencent.imsdk.TIMMessage;
import com.zjw.hyphenateui.MainApplication;
import com.zjw.hyphenateui.ui.MainActivity;

/**
 * 封装环信库与主项目交互的方法
 */
public class HyphenateLibraryCallBackHandle implements HyphenateLibraryCallBack {


    @Override
    public void goUserHome(Context context,String userId) {

    }

    @Override
    public void onNewMsg(TIMMessage message) {
        if(MainApplication.isAppBackground()){  //是否是后台运行 显示提醒通知
            Intent intent = new Intent(MainApplication.getAppContext(), MainActivity.class);
            intent.addCategory(Intent.CATEGORY_LAUNCHER);
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP);
            PendingIntent pendingIntent = PendingIntent.getActivity(MainApplication.getAppContext(), 1, intent,
                    PendingIntent.FLAG_UPDATE_CURRENT);
            NotificationHelper.getInstance().sendNotification(NotificationConstants.HYPHENATE_NOTIFCATION_ID,"环信库", "您有新的聊天消息!", pendingIntent);
        }
    }

    @Override
    public void goGroupInfo(Context context, String groupId) {

    }
}
